package engine.colliders;

import engine.entities.Entity;
import engine.entities.Spatial;

public class Border implements CollisionResolver {
	int width;
	int height;

	public Border(int width, int height) {
		this.width = width;
		this.height = height;
	}

	@Override
	public void updateCollision(Entity a, Entity b) {
		Spatial spatial = a.getSpatial();
		float x = spatial.getX();
		float y = spatial.getY();
		float width = spatial.getWidth();
		float height = spatial.getHeight();

		if (x < 0) {
			spatial.setX(0);
			spatial.setSpeedX(0);
		}
		if (y < 0) {
			spatial.setY(0);
			spatial.setSpeedY(0);
		}
		if (x + width > this.width) {
			spatial.setX(this.width - width);
			spatial.setSpeedX(0);
		}
		if (y + height > this.height) {
			spatial.setY(this.height - height);
			spatial.setSpeedY(0);
		}
	}

	@Override
	public boolean precondMet(Entity a, Entity b) {
		if (a == b)
			return true;
		else
			return false;
	}

}
